﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
	<meta charset="utf-8" />
    <link rel="stylesheet" href="Content/bootstrap.css" />
</head>
<body>
    <div id="app" class="container-fluid" style="margin-top: 20px;">
        <div class="col-sm-9">
            <table class="table table-bordered table-striped table-hover">
                <thead>
                    <tr>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>年龄</th>
                        <th>联系地址</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="item in tblist">
                        <td>{{ item.Name }}</td>
                        <td>{{ item.Sex }}</td>
                        <td>{{ item.Age }}</td>
                        <td>{{ item.Address }}</td>
                        <td>
                            <input type="button" class="btn btn-warning" @click="del($index)" value="删除" />
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="col-sm-3">
            <form>
                <div class="form-group">
                    <label>姓名</label>
                    <input type="text" class="form-control" v-model="tmpperson.Name" required />
                </div>
                <div class="form-group">
                    <label>性别</label>
                    <select class="form-control" v-model="tmpperson.Sex" required>
                        <option value="1">男</option>
                        <option value="2">女</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>年龄</label>
                    <input type="number" class="form-control" v-model="tmpperson.Age" required />
                </div>
                <div class="form-group">
                    <label>联系地址</label>
                    <input type="text" class="form-control" v-model="tmpperson.Address" />
                </div>
                <div class="form-group text-center">
                    <input type="button" class="btn btn-primary btn-lg" value="添加" @click="add" />
                </div>
            </form>
        </div>
    </div>

    <script src="Scripts/vue.js"></script>
    <script src="Scripts/jquery-1.9.1.js"></script>
    <script src="Scripts/bootstrap.js"></script>
    <script>

        //v-bind那个示例,现在的2.0版本里循环是基于1的,所以不能使用n+1,如果使用n+1,页码就变成从2-11,所以1不会被active.
        new Vue({
            el: "#app",
            data: {
                tmpperson: {
                    Name: "",
                    Sex: "",
                    Age: "",
                    Address: ""
                },
                tblist: new Array()
            },
            methods: {
                add: function () {
                    this.tblist.push(this.tmpperson);
                    this.tmpperson = {
                        Name: "",
                        Sex: "",
                        Age: "",
                        Address: ""
                    };
                },
                del: function (index) {
                    this.tblist.splice(index - 1, 1);
                }
            }
        });
    </script>
</body>
</html>
